<?php

namespace app\erp\controller;

class QueryArdetail extends Base
{
    public function __construct($starttime, $endtime,$client_id,$client_secret,$account_id,$user_name)
    {
        parent::__construct($client_id, $client_secret,$account_id,$user_name);

        $this->starttime = $starttime;
        $this->endtime   = $endtime;
    }
    public function run($bdl_contactunit_number,$orgnumber)
    {


        if(in_array($this->account_id,[1808778350425014272,1845044874454237184]))
        {
            $method = "v2/bdl/bdl_bal/bdl_bal_ardetail/queryArdetail";
        }else{
            $method = "v2/bdl/bdl_balance/bdl_arbalancedetail/queryArdetail";
        }
        $method = $this->datacenter_data['fk_bdl_queryardetail'];

        $fullurl = $this->url . $method;

        $response_data = [
            'data'      => [
                'starttime'             => $this->starttime,
                'endtime'               => $this->endtime,
                'bdl_contactunit_number'=> $bdl_contactunit_number,
//                'org_number'             => $orgnumber,
            ],
            'pageNo'    => $this->pageNo,
            'pageSize'  => $this->pageSize,
        ];


        $this->curl->setHeader("Content-Type", "application/json");
        $this->curl->setHeader("accesstoken", $this->getToken());
        $this->curl->setHeader("Idempotency-Key", uuid());

        $res = $this->curl->post($fullurl, json_encode($response_data));

        if ($res && is_object($res) && $res->status == 1)
        {
            if($res->data->totalCount > 0){

                return [
                    'data'  => $res->data->rows,
                    'code'  => 1,
                    'msg'   => '请求成功'
                ];
            }else{
                return [
                    'code'  => 2,
                    'mes'   => '没有数据'
                ];
            }

        }else{
            return [
                'code' => 0,
                'mes'  => '请求失败'
            ];
        }
    }



}